<!--
 * @Author: Bennty
 * @Date: 2024-07-17 13:02:24
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-09-12 17:27:00
 * @Description: 请填写简介
-->
<template>
    <el-dialog v-model="props.visible" title="退还定金" width="20%" @close="handleClose" destroy-on-close>
        <el-form :model="formData" ref="formRef">
            <el-row>
                <el-col :span="12">
                    <el-form-item label="客户名称">{{ props.data.customerName }}</el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="合同定金">{{ props.data.contractDeposit }}</el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="合同总额">{{ props.data.contractAmount }}</el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="剩余定金">{{ props.data.depositSurplusAmount || 0 }}</el-form-item>
                </el-col>
            </el-row>
            <el-form-item label="申请退还定金" prop="returnAmount">
                <el-input v-model="formData.returnAmount" placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item label="备注" prop="remark">
                <el-input v-model="formData.remark" type="textarea" maxlength="50" show-word-limit></el-input>
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button  type="primary" @click="handleSubmit">确 定</el-button>
                <el-button @click="handleClose">取 消</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import type { FormInstance } from 'element-plus';
import { refundDepositsApi } from '@/api/sj/contract-crm/index';

const formRef = ref<FormInstance>();
const props = defineProps(['visible','data']);
const emits = defineEmits(['close','submit']);
const formData = ref(
    {
        returnAmount: undefined,
        remark: undefined
    }
);

const handleSubmit = async ()=>{
    const submitData = {
        ...formData.value, 
        contractId:props.data.id, 
        customerId: props.data.customerId, 
        customerName: props.data.customerName,
        customerAmount: props.data.contractAmount,
        contractDeposit: props.data.contractDeposit
    };
    await refundDepositsApi(submitData).then((result)=>{
        if(result.code==200){
            emits('submit',true);
            handleClose();
        }else{
            emits('submit',false);
        }
    });
};

const handleClose = ()=>{
    formRef.value?.resetFields();
    emits('close');
};
</script>

<style lang="scss" scoped>
.dialog-footer{
    display:flex;
    justify-content: center;
}
</style>